import * as chart from './echarts.js';

export function getEcharts() {
    return chart


}

export class HmInitChart {
    constructor(ctx) {
        this.myCharts = chart.init(ctx)
    }

    setOption(option) {
        this.myCharts.setOption({ animation: false, ...option })
    }
    getDataURL(){
     let url= this.myCharts.getDataURL({
            type:'png',
            pixelRatio: 1,
        })
        return url
    }
    onTouchEvent(event, fun) {
        this._initEvent(event)
        this.myCharts.on('click', { dataType: 'node' }, (params) => {

        });
    }

    // 处理事件机制
    _initEvent(event) {
        const eventNames = [{
            type: '0',
            ecName: 'mousedown'
        }, {
            type: '2',
            ecName: 'mousemove'
        }, {
            type: '1',
            ecName: 'mouseup'
        }, {
            type: '1',
            ecName: 'click'
        }];
        eventNames.forEach(name => {
            if (event.type == name.type) {
                console.log('asasa123',JSON.stringify(event))
                const touch = event.touches[0];
                this.myCharts.getZr().handler.dispatch(name.ecName, {
                    zrX: name.type === 'tap' ? touch.screenX : touch.x,
                    zrY: name.type === 'tap' ? touch.screenY : touch.y,
                    preventDefault: () => {
                    },
                    stopImmediatePropagation: () => {
                    },
                    stopPropagation: () => {
                    }
                });
            }
        });
    }
}
